package com.lazily.static_;


/**
 * @Author:  GZQ
 * @date:  2025/1/12 23:10
 * @description: 类变量和类方法的练习2
 */

public class StaticExercise02 {
    public static void main(String[] args) {
        System.out.println("Number of total is " + Person.getTotalPerson()); // 0
        Person p1 = new Person();
        System.out.println("Number of total is " + Person.getTotalPerson()); // 1
    }
}

class Person {

    private int id;
    private static int total = 0;

    public Person() {
        total++; // total = 1
        id = total; // id = 1
    }

    public static int getTotalPerson() {
        // id++; 不能在静态方法中调用非静态成员变量

        return total;
    }
}
